package com.glela.api.pay.yeepay.component.impl;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.glela.api.pay.yeepay.component.YeePay;
import com.glela.api.pay.yeepay.model.YeePayAliModel;
import com.glela.api.pay.yeepay.model.YeePayBaseModel;
import com.glela.api.pay.yeepay.model.YeePayDivideModel;
import com.glela.api.pay.yeepay.model.YeePayNetSilverModel;
import com.glela.api.pay.yeepay.model.YeePayQueryDivideModel;
import com.glela.api.pay.yeepay.model.YeePayRefundModel;
import com.glela.api.pay.yeepay.model.YeePayWeChatModel;
import com.glela.common.constant.YeePayURLConstants;
import com.glela.common.util.Config;
import com.glela.common.util.HttpUtil;
import com.glela.common.util.JsonUtil;
import com.glela.common.util.NumberUtil;
import com.glela.common.util.YeePayAESUtil;
import com.glela.common.util.YeePayDigest;

/**
 * 
 * @author MaoZeYao
 *
 */
@Component("yeePay")
public class YeePayImpl implements YeePay {

	/**
	 * 1.0
	 * 中介支付宝
	 */
	@Override
	public String yeePayTradeAlipay(YeePayAliModel model) {
		// TODO Auto-generated method stub
		String result = "";
		try {
			String data = getYeePayAlipayString(model);
			String content = "customernumber=" + YeePay.CUSTOMER_NUMBER + "&data=" + data;
			String url = "https://o2o.yeepay.com/zgt-api/api/pay";
			result = HttpUtil.doPost(content, url, "application/x-www-form-urlencoded");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return YeePayAESUtil.decrypt(JSONObject.parseObject(result).get("data").toString(), YeePay.SECRET_KEY.substring(0, 16));
	}
	
	/**
	 * 2.0
	 * 中介快捷支付请求
	 * @throws Exception 
	 */
	@Override
	public String yeePayTradeNetSilver(YeePayNetSilverModel model) {
		// TODO Auto-generated method stub
		String result = "";
		try {
			String data = getYeePayNetSilverString(model);
			String content = "customernumber=" + YeePay.CUSTOMER_NUMBER + "&data=" + data;
			String url = "https://o2o.yeepay.com/zgt-api/api/pay";
			result = HttpUtil.doPost(content, url, "application/x-www-form-urlencoded");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return YeePayAESUtil.decrypt(JSONObject.parseObject(result).get("data").toString(), YeePay.SECRET_KEY.substring(0, 16));
	}
	
	/**
	 * 3.0
	 * 中介微信请求
	 */
	@Override
	public String yeePayTradeWeChat(YeePayWeChatModel model) {
		// TODO Auto-generated method stub
		String result = "";
		try {
			String data = getYeePayWeChatString(model);
			String content = "customernumber=" + YeePay.CUSTOMER_NUMBER + "&data=" + data;
			String url = "https://o2o.yeepay.com/zgt-api/api/pay";
			result = HttpUtil.doPost(content, url, "application/x-www-form-urlencoded");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return YeePayAESUtil.decrypt(JSONObject.parseObject(result).get("data").toString(), YeePay.SECRET_KEY.substring(0, 16));
	}
	
	/**
	 * 4.0
	 * 找中介退款
	 */
	@Override
	public String yeePayRefund(YeePayRefundModel model) {
		// TODO Auto-generated method stub
		String result = "";
		try {
			String data = getYeePayRefundString(model);
			String content = "customernumber=" + YeePay.CUSTOMER_NUMBER + "&data=" + data;
			String url = "https://o2o.yeepay.com/zgt-api/api/refund";
			result = HttpUtil.doPost(content, url, "application/x-www-form-urlencoded");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return YeePayAESUtil.decrypt(JSONObject.parseObject(result).get("data").toString(), YeePay.SECRET_KEY.substring(0, 16));
	}
	
	/**
	 * 4.0
	 * 找中介退款
	 */
	@Override
	public String yeePayQueryRefund(YeePayRefundModel model) {
		// TODO Auto-generated method stub
		String result = "";
		try {
			String data = getYeePayQueryRefundString(model);
			String content = "customernumber=" + YeePay.CUSTOMER_NUMBER + "&data=" + data;
			String url = "https://o2o.yeepay.com/zgt-api/api/queryRefund";
			result = HttpUtil.doPost(content, url, "application/x-www-form-urlencoded");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return YeePayAESUtil.decrypt(JSONObject.parseObject(result).get("data").toString(), YeePay.SECRET_KEY.substring(0, 16));
	}
	
	/**
	 * 分账接口
	 */
	@Override
	public String yeePayDivide(YeePayDivideModel model) {
		// TODO Auto-generated method stub
		String result = "";
		try {
			String data = getDivideString(model);
			String content = "customernumber=" + YeePay.CUSTOMER_NUMBER + "&data=" + data;
			String url = "https://o2o.yeepay.com/zgt-api/api/divide";
			result = HttpUtil.doPost(content, url, "application/x-www-form-urlencoded");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return YeePayAESUtil.decrypt(JSONObject.parseObject(result).get("data").toString(), YeePay.SECRET_KEY.substring(0, 16));
	}
	/**
	* 分账查询接口
	* @author gaoweiqi
	* @date 2017年10月17日 17:44:05
	*
	**/
	@Override
	public String yeePayQueryDivide(YeePayQueryDivideModel model) {
		String result = "";
		try {
			String data = getQueryDivideString(model);
			String content = "customernumber=" + YeePay.CUSTOMER_NUMBER + "&data=" + data;
			String url = "https://o2o.yeepay.com/zgt-api/api/queryDivide";
			result = HttpUtil.doPost(content, url, "application/x-www-form-urlencoded");
		} catch (Exception e) {
			try {
				return "model:"+JsonUtil.toJson(model)+"message:"+e.getMessage().substring(0, e.getMessage().length()>100?100:e.getMessage().length());
			} catch (IOException e1) {
				return ""+model;
			}
		}
		return YeePayAESUtil.decrypt(JSONObject.parseObject(result).get("data").toString(), YeePay.SECRET_KEY.substring(0, 16));
	}
	
	public Map<String,Double> parsingYeePayDivide(String divideString) throws Exception{
		Map<String,Double> divideCompany= new HashMap<String,Double>();
		 String[] strs=divideString.split("&");
		  for(String str:strs){
			  if(str.endsWith("COMPLETED")){
				  String[] Divide=str.split(",")[1].split("[|]");
				  for(String Di:Divide){
					 String company= Di.substring(0, Di.indexOf(":"));
					 String amount= Di.substring( Di.indexOf("amount")+6);
					  if(divideCompany.containsKey(company)){
						  divideCompany.put(company,NumberUtil.add(divideCompany.get(company),Double.parseDouble(amount)));
					  }else{
						  divideCompany.put(company,Double.parseDouble(amount));
					  }
				  }
			  }
		  }
		return divideCompany;
	}
	
	/**
	 * 微信扫码支付
	 */
	@Override
	public String yeePayTradeWeChatQRCode(YeePayWeChatModel model) {
		// TODO Auto-generated method stub
		String result = "";
		try {
			model.setPayproducttype("WECHATU"); // 微信扫码
			String data = getYeePayWeChatString(model);
			String content = "customernumber=" + YeePay.CUSTOMER_NUMBER + "&data=" + data;
			String url = "https://o2o.yeepay.com/zgt-api/api/pay";
			result = HttpUtil.doPost(content, url, "application/x-www-form-urlencoded");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return YeePayAESUtil.decrypt(JSONObject.parseObject(result).get("data").toString(), YeePay.SECRET_KEY.substring(0, 16));
	}

	/**
	 * 1.1
	 * 生成中介支付宝的data
	 * @param model
	 * @return
	 */
	protected String getYeePayAlipayString (YeePayAliModel model) {
		String data = "";
		try {
			String customernumber = YeePay.CUSTOMER_NUMBER; // 主账号商户编号
			String requestid = model.getRequestid(); // 订单号必须在该商编下唯一，由商户输入
			String amount = model.getAmount(); // 单位：元.必须大于等于0.01
			String assure = model.getAssure(); // 1 – 担保交易 0 – 非担保交易
			String productname = model.getProductname();// 商品名称
			String productcat = model.getProductcat(); // 商品类别
			String productdesc = model.getProductdesc(); // 商品描述
			String divideinfo = model.getDivideinfo(); // "10013422494:0.0015|10013422911:0.0125"
			String callbackurl = model.getCallbackurl(); // 服务器点对点通知地址
			String webcallbackurl = model.getWebcallbackurl();
			String bankid = model.getBankid(); // 该参数仅当支付产品类别为快捷,即参数payproducttype=SALES时 才有效
			String period = model.getPeriod(); //
			String memo = model.getMemo(); // 商户备注
			String hmac = ""; // 签名信息
			String keyForAes = YeePay.SECRET_KEY.substring(0, 16);
			String[] stringArray = { customernumber, requestid, amount, assure, productname, productcat, productdesc,
					divideinfo, callbackurl, webcallbackurl, bankid, period, memo };
			// 签名完成
			hmac = YeePayDigest.getHmac(stringArray, YeePay.SECRET_KEY);
			
			// 订单的有效时间 ！！！！！！！！！！！！！！！！！！！！！！！
			String orderexpdate = model.getOrderexpdate();
		
			Map<String, String> dataMap = new HashMap<String, String>();
			dataMap.put("customernumber", customernumber);
			dataMap.put("requestid", requestid);
			dataMap.put("amount", amount);
			dataMap.put("assure", assure);
			dataMap.put("productname", productname);
			dataMap.put("productcat", productcat);
			dataMap.put("productdesc", productdesc);
			dataMap.put("divideinfo", divideinfo);
			dataMap.put("callbackurl", callbackurl);
			dataMap.put("webcallbackurl", webcallbackurl);
			dataMap.put("bankid", bankid);
			dataMap.put("period", period);
			dataMap.put("memo", memo);
			dataMap.put("orderexpdate", orderexpdate);
			// 支付宝参数
			dataMap.put("payproducttype", "ALIPAYAPP");
			dataMap.put("ip", model.getIp());
			
			dataMap.put("directcode", model.getDirectcode());
			
			dataMap.put("hmac", hmac);
			String dataJsonString = JSONObject.toJSONString(dataMap); // 生成data
			// AES加密
			data = YeePayAESUtil.encrypt(dataJsonString, keyForAes);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return data;
	}
	
	/**
	 * 2.1
	 * 生成中介快捷的data
	 * @param model
	 * @return
	 */
	protected String getYeePayNetSilverString (YeePayNetSilverModel model) {
		String data = "";
		try {
			String customernumber = YeePay.CUSTOMER_NUMBER; // 主账号商户编号
			String requestid = model.getRequestid(); // 订单号必须在该商编下唯一，由商户输入
			String amount = model.getAmount(); // 单位：元.必须大于等于0.01
			String assure = model.getAssure(); // 1 – 担保交易 0 – 非担保交易
			String productname = model.getProductname();// 商品名称
			String productcat = model.getProductcat(); // 商品类别
			String productdesc = model.getProductdesc(); // 商品描述
			String divideinfo = model.getDivideinfo(); // "10013422494:0.0015|10013422911:0.0125"
			String callbackurl = model.getCallbackurl(); // 服务器点对点通知地址
			String webcallbackurl = model.getWebcallbackurl();
			String bankid = model.getBankid(); // 该参数仅当支付产品类别为快捷,即参数payproducttype=SALES时 才有效
			String period = model.getPeriod(); //
			String memo = model.getMemo(); // 商户备注
			String hmac = ""; // 签名信息
			String keyForAes = YeePay.SECRET_KEY.substring(0, 16);
			String[] stringArray = { customernumber, requestid, amount, assure, productname, productcat, productdesc,
					divideinfo, callbackurl, webcallbackurl, bankid, period, memo };
			// 签名完成
			hmac = YeePayDigest.getHmac(stringArray, YeePay.SECRET_KEY);
			
			// 订单的有效时间 ！！！！！！！！！！！！！！！！！！！！！！！
			String orderexpdate = model.getOrderexpdate();
			
			// 以下参数为快捷支付时才需要传递
			String payproducttype = model.getPayproducttype(); // 快捷固定值：SALES；当该参数 的值为SALES时，表示支付产品 类型为快捷支付。
			String userno = model.getUserno(); // 商户用来表示用户的唯一标识
			String cardname = model.getCardname(); // 持卡人姓名，如传送过来则会限 制用户只能用对应这个开户名的 银行卡支付
			String idcard = model.getIdcard(); // 身份证号
			String bankcardnum = model.getBankcardnum(); // 银行卡号
			String mobilephone = model.getMobilephone(); // 银行预留手机号
			
			Map<String, String> dataMap = new HashMap<String, String>();
			dataMap.put("customernumber", customernumber);
			dataMap.put("requestid", requestid);
			dataMap.put("amount", amount);
			dataMap.put("assure", assure);
			dataMap.put("productname", productname);
			dataMap.put("productcat", productcat);
			dataMap.put("productdesc", productdesc);
			dataMap.put("divideinfo", divideinfo);
			dataMap.put("callbackurl", callbackurl);
			dataMap.put("webcallbackurl", webcallbackurl);
			dataMap.put("bankid", bankid);
			dataMap.put("period", period);
			dataMap.put("memo", memo);
			
			dataMap.put("orderexpdate", orderexpdate);
			
			// 快捷参数
			dataMap.put("payproducttype", payproducttype);
			dataMap.put("userno", userno);
			dataMap.put("cardname", cardname);
			dataMap.put("idcard", idcard);
			dataMap.put("bankcardnum", bankcardnum);
			dataMap.put("mobilephone", mobilephone);
			
			dataMap.put("ip", model.getIp());
			dataMap.put("directcode", model.getDirectcode());
			
			dataMap.put("hmac", hmac);
			
			String dataJsonString = JSONObject.toJSONString(dataMap); // 生成data
			// AES加密
			data = YeePayAESUtil.encrypt(dataJsonString, keyForAes);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return data;
	}
	
	/**
	 * 3.1
	 * 生成中介微信的data
	 * @param model
	 * @return
	 */
	protected String getYeePayWeChatString (YeePayWeChatModel model) {
		String data = "";
		try {
			String customernumber = YeePay.CUSTOMER_NUMBER; // 主账号商户编号
			String requestid = model.getRequestid(); // 订单号必须在该商编下唯一，由商户输入
			String amount = model.getAmount(); // 单位：元.必须大于等于0.01
			String assure = model.getAssure(); // 1 – 担保交易 0 – 非担保交易
			String productname = model.getProductname();// 商品名称
			String productcat = model.getProductcat(); // 商品类别
			String productdesc = model.getProductdesc(); // 商品描述
			String divideinfo = model.getDivideinfo(); // "10013422494:0.0015|10013422911:0.0125"
			String callbackurl = model.getCallbackurl(); // 服务器点对点通知地址
			String webcallbackurl = model.getWebcallbackurl();
			String bankid = model.getBankid(); // 该参数仅当支付产品类别为快捷,即参数payproducttype=SALES时 才有效
			String period = model.getPeriod(); //
			String memo = model.getMemo(); // 商户备注
			String hmac = ""; // 签名信息
			String keyForAes = YeePay.SECRET_KEY.substring(0, 16);
			String[] stringArray = { customernumber, requestid, amount, assure, productname, productcat, productdesc,
					divideinfo, callbackurl, webcallbackurl, bankid, period, memo };
			// 签名完成
			hmac = YeePayDigest.getHmac(stringArray, YeePay.SECRET_KEY);
			
			// 订单的有效时间 ！！！！！！！！！！！！！！！！！！！！！！！
			String orderexpdate = model.getOrderexpdate();
			
			// 以下参数为快捷支付时才需要传递
			String payproducttype = model.getPayproducttype(); // 快捷固定值：SALES；当该参数 的值为SALES时，表示支付产品 类型为快捷支付。
			String userno = model.getUserno(); // 商户用来表示用户的唯一标识
			
			Map<String, String> dataMap = new HashMap<String, String>();
			dataMap.put("customernumber", customernumber);
			dataMap.put("requestid", requestid);
			dataMap.put("amount", amount);
			dataMap.put("assure", assure);
			dataMap.put("productname", productname);
			dataMap.put("productcat", productcat);
			dataMap.put("productdesc", productdesc);
			dataMap.put("divideinfo", divideinfo);
			dataMap.put("callbackurl", callbackurl);
			dataMap.put("webcallbackurl", webcallbackurl);
			dataMap.put("bankid", bankid);
			dataMap.put("period", period);
			dataMap.put("memo", memo);
			
			dataMap.put("orderexpdate", orderexpdate);
			
			// 微信参数
			dataMap.put("payproducttype", payproducttype);
			if ("WAP_WECHATG".equals(model.getDirectcode())) {
				dataMap.put("openid", userno);
				dataMap.put("appid", Config.getString("wechat.appId"));
			}
			dataMap.put("ip", model.getIp());
			dataMap.put("directcode", model.getDirectcode());
			
			dataMap.put("hmac", hmac);
			
			String dataJsonString = JSONObject.toJSONString(dataMap); // 生成data
			// AES加密
			data = YeePayAESUtil.encrypt(dataJsonString, keyForAes);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return data;
	}
	
	/**
	 * 必须签名的参数
	 * @param model
	 * @return
	 */
	protected String commonalityArgs (YeePayBaseModel model) {
		String customernumber = YeePay.CUSTOMER_NUMBER; // 主账号商户编号
		String requestid = model.getRequestid(); // 订单号必须在该商编下唯一，由商户输入
		String amount = model.getAmount(); // 单位：元.必须大于等于0.01
		String assure = model.getAssure(); // 1 – 担保交易 0 – 非担保交易
		String productname = model.getProductname();// 商品名称
		String productcat = model.getProductcat(); // 商品类别
		String productdesc = model.getProductdesc(); // 商品描述
		String divideinfo = model.getDivideinfo(); // "10013422494:0.0015|10013422911:0.0125"
		String callbackurl = model.getCallbackurl(); // 服务器点对点通知地址
		String webcallbackurl = model.getWebcallbackurl();
		String bankid = model.getBankid(); // 该参数仅当支付产品类别为网银,即参数payproducttype=SALES时 才有效
		String period = model.getPeriod(); //
		String memo = model.getMemo(); // 商户备注
		String hmac = ""; // 签名信息
		String[] stringArray = { customernumber, requestid, amount, assure, productname, productcat, productdesc,
				divideinfo, callbackurl, webcallbackurl, bankid, period, memo };
		// 签名完成
		hmac = YeePayDigest.getHmac(stringArray, YeePay.SECRET_KEY);
		return hmac;
	}
	
	/**
	 * 中介退款参数封装
	 * @param model
	 * @return
	 */
	protected String getYeePayRefundString(YeePayRefundModel model) {
		// TODO Auto-generated method stub
		
		String customernumber = YeePay.CUSTOMER_NUMBER; //
		String requestid = model.getRequestid(); // 退款请求号   商户传入，必须在该商编下唯一
		String orderrequestid  = model.getOrderrequestid(); // 将被退款的订单号
		String amount = model.getAmount(); // 退款金额，单位：元
		String divideinfo = model.getDivideinfo();// 子账户退款详情   分账的人
		String confirm = model.getConfirm(); // 确认退款  固定值1
		String memo = model.getMemo(); // 退款备注
		String hmac = ""; // 签名信息
		
		String keyForAes = YeePay.SECRET_KEY.substring(0, 16);
		String[] stringArray = { customernumber, requestid, orderrequestid, amount, divideinfo, confirm, memo };
		
		hmac = YeePayDigest.getHmac(stringArray, YeePay.SECRET_KEY);
		
		Map<String, String> dataMap = new HashMap<String, String>();
		dataMap.put("customernumber", customernumber);
		dataMap.put("requestid", requestid);
		dataMap.put("orderrequestid", orderrequestid);
		dataMap.put("amount", amount);
		dataMap.put("divideinfo", divideinfo);
		dataMap.put("confirm", confirm);
		dataMap.put("memo", memo);
		dataMap.put("hmac", hmac);
		
		String dataJsonString = JSONObject.toJSONString(dataMap); // 生成data
		// AES加密
		String data = YeePayAESUtil.encrypt(dataJsonString, keyForAes);
		return data;
	}
	/**
	 * 退款查询参数
	 * @param model
	 * @return
	 */
	protected String getYeePayQueryRefundString(YeePayRefundModel model) {
		// TODO Auto-generated method stub
		
		String customernumber = YeePay.CUSTOMER_NUMBER; //
		String requestid = model.getRequestid();  
		String orderrequestid  = model.getOrderrequestid();  
		String hmac = ""; // 签名信息
		
		String keyForAes = YeePay.SECRET_KEY.substring(0, 16);
		String[] stringArray = { customernumber, requestid, orderrequestid};
		
		hmac = YeePayDigest.getHmac(stringArray, YeePay.SECRET_KEY);
		
		Map<String, String> dataMap = new HashMap<String, String>();
		dataMap.put("customernumber", customernumber);
		dataMap.put("requestid", requestid);
		dataMap.put("orderrequestid", orderrequestid);
		dataMap.put("hmac", hmac);
		
		String dataJsonString = JSONObject.toJSONString(dataMap); // 生成data
		// AES加密
		String data = YeePayAESUtil.encrypt(dataJsonString, keyForAes);
		return data;
	}
	
	/**
	 * 分账参数构造
	 * @param model
	 * @return
	 */
	protected String getDivideString (YeePayDivideModel model) {
		String customernumber = YeePay.CUSTOMER_NUMBER; // 主账号商户编号
		String requestid = model.getRequestid(); //唯一，由商户输入
		String orderrequestid = model.getOrderrequestid(); // 支付成功的订单号
		String divideinfo = model.getDivideinfo(); // "10013422494:0.0015|10013422911:0.0125"
		String callbackurl = model.getCallbackurl(); // 服务器点对点通知地址
		String hmac = ""; // 签名信息
		
		String keyForAes = YeePay.SECRET_KEY.substring(0, 16);
		String[] stringArray = { customernumber, requestid, orderrequestid, divideinfo };
		
		// 签名完成
		hmac = YeePayDigest.getHmac(stringArray, YeePay.SECRET_KEY);
		
		Map<String, String> dataMap = new HashMap<String, String>();
		dataMap.put("customernumber", customernumber);
		dataMap.put("requestid", requestid);
		dataMap.put("orderrequestid", orderrequestid);
		dataMap.put("divideinfo", divideinfo);
		dataMap.put("callbackurl", callbackurl);
		dataMap.put("hmac", hmac);
		
		String dataJsonString = JSONObject.toJSONString(dataMap); // 生成data
		// AES加密
		String data = YeePayAESUtil.encrypt(dataJsonString, keyForAes);
		return data;
	}
	/**
	 * 分账查询参数构造
	 * @param model
	 * @return
	 */
	protected String getQueryDivideString(YeePayQueryDivideModel model) {
			model.setCustomernumber(YeePay.CUSTOMER_NUMBER);// 主账号商户编号
			String hmac = ""; // 签名信息
			String keyForAes = YeePay.SECRET_KEY.substring(0, 16);
			String[] stringArray = { model.getCustomernumber(), model.getOrderrequestid()};
			// 签名完成
			hmac = YeePayDigest.getHmac(stringArray, YeePay.SECRET_KEY);
			
			Map<String, String> dataMap = new HashMap<String, String>();
			dataMap.put("customernumber", model.getCustomernumber());
			dataMap.put("orderrequestid", model.getOrderrequestid());
			dataMap.put("hmac", hmac);
			
			String dataJsonString = JSONObject.toJSONString(dataMap); // 生成data
			// AES加密
			String data = YeePayAESUtil.encrypt(dataJsonString, keyForAes);
			return data;
	}

	public String yeePayQueryOrder(Map<Object, Object> requestMap) {
    String customernumber =YeePay.CUSTOMER_NUMBER;// 主账号商户编号
	String requestid = requestMap.get("requestid").toString(); //商户订单号
	String hmac = ""; // 签名信息
	
	String keyForAes = YeePay.SECRET_KEY.substring(0, 16);
	String[] stringArray = { customernumber,requestid };
	
	// 签名完成
	hmac = YeePayDigest.getHmac(stringArray, YeePay.SECRET_KEY);
	
	Map<String, String> dataMap = new HashMap<String, String>();
	dataMap.put("customernumber", customernumber);
	dataMap.put("requestid", requestid);
	dataMap.put("hmac", hmac);
	
	String dataJsonString = JSONObject.toJSONString(dataMap); // 生成data
	// AES加密
	String data = YeePayAESUtil.encrypt(dataJsonString, keyForAes);
	String result = "";
	try {
		String content = "customernumber=" + YeePay.CUSTOMER_NUMBER + "&data=" + data;
		String url = YeePayURLConstants.YEEPAY_QUERYORDER;
		result = HttpUtil.doPost(content, url, "application/x-www-form-urlencoded");
	} catch (Exception e) {
		e.printStackTrace();
	}
	return YeePayAESUtil.decrypt(JSONObject.parseObject(result).get("data").toString(), YeePay.SECRET_KEY.substring(0, 16));
	}
}

